<template>
    <bi-form ref="form" >
        <div class="row g-2" >
            <bi-card  title="">
                <bi-form-item label="域名" >
                    <bi-input v-model="formData.domain" :placeholder="domainPlaceholder" />
                </bi-form-item>
            </bi-card>
            <bi-card  title="缓存">
                <bi-form-item label="缓存" >
                    <bi-switch v-model="formData.cache" />
                </bi-form-item>

                <bi-form-item label="缓存时间" v-if="formData.cache">
                    <bi-radio v-model="formData.cacheTime" :option="cacheOption" />
                </bi-form-item>
            </bi-card>

            <bi-card  title="资源URL">
                <bi-form-item label="上传文件" description="如果网站运行目录不在根路径，请设置用于显示上传文件网址" >
                    <bi-input v-model="formData.uploadFileUrl" ></bi-input>
                </bi-form-item>
                <bi-form-item label="Webpack" >
                    <bi-input v-model="formData.webpackUrl" ></bi-input>
                </bi-form-item>
                <template #footer>
                    <bi-button icon="fa-save" @click="saveSetting"  type="primary">保存</bi-button>
                </template>
            </bi-card>
        </div>
    </bi-form>
</template>


<script>
export default {
    data(){

        let formData = {
            domain:'',
            uploadFileUrl:'',
            webpackUrl:'',
            cache:true,
            cacheTime:3600,
        }

        let domainPlaceholder = location.hostname;

        let cacheOption = [
            {label:'5分钟',value:5*60},
            {label:'30分钟',value:30*60},
            {label:'1小时',value:3600},
            {label:'2小时',value:2*3600},
            {label:'1天',value:24*3600},
        ]

        this.$assign(formData,this.item);

        return {
            formData,
            cacheOption,
            domainPlaceholder
        }
    },
    props:{
        item:Object
    },
    methods:{
        saveSetting(){
            if (this.$refs.form.check()){
                this.$ajax({
                    url:this.$url({controller:'admin.setting',action:'saveBase'}),
                    data:{
                        ...this.formData
                    },
                    success:(res)=>{
                        this.$toast('保存成功');
                    }
                });
            }
        },
    }
}
</script>